<?php
require "home/model/IndexModel.php";
require "home/controller/Controller.php";
	class IndexController  extends Controller{
		function __construct(){
			parent::__construct();
		}
		function index(){
			$model=new IndexModel();
			$data=$model->getList();
			//return $data;

			$this->assign('foods',$data);
			$this->display();//送到view层显示数据
		}
		function listall(){
			$tid=$_GET['tid'];
			$model=new IndexModel();
			$data=$model->getListall($tid);
			//return $data;

			$this->assign('listall',$data);
			$this->display();//送到view层显示数据
		}
		function content(){
			$vid=$_GET['vid'];
			$model=new IndexModel();
			$data=$model->getContent($vid);

			$this->assign('content',$data);
			$this->display();//送到view层显示数据
		}
		function reguser(){
			$this->display();
		}
		function adduser(){
			$data=$_POST;
			$file=$_FILES;
			$model=new IndexModel();
			$result=$model->adduser($data,$file);
			if ($result) {
				echo "注册成功，3秒后返回首页";
				header("refresh:3;url='index.php?c=index&m=index'");
			}else{
				echo "注册失败，3秒后返回注册页面重新注册";
				header("refresh:3;url='index.php?c=index&m=reguser'");
			}

		}
		function login(){
			$this->display();
		}
		function dologin(){
			$uname=$_POST["uname"];
			$password=$_POST["password"];
			$model=new IndexModel();
			$result=$model->dologin($uname,$password);
			 if ($result) {
        		echo "欢迎您";
        		echo $uname;
       			 $_SESSION["uname"]=$uname;
       			 $_SESSION["password"]=$password;
       			header("refresh:3;url='index.php?c=index&m=index'");
    			} else
       			 echo "请重试，3秒后返回注册页面重新登陆";

		}
	/*	
		function search(){
			$data=$_POST;
			$model=new IndexModel();
			$result=$model->search($data);
			if ($result) {
				$row=$result;
				$vid=$row['vid'];
				header("refresh:3;url='index.php?c=index&m=searchlist&vid=$vid'");
    			} else
       			 echo "没有搜索到该内容，3秒后返回";
   

		}*/
		function searchlist(){
			$this->display();
			$tid=$_GET['tid'];
			$model=new IndexModel();
			$data=$model->getListall($tid);
			//return $data;

			$this->assign('listall',$data);
			$this->display();
		}
		function logout(){
             session_start();
             session_destroy();
       		 echo "注销成功";
       		 header("refresh:2;url='index.php?c=index&m=index'");


		}
	}
?>